#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;

int n, m;
int a[N], b[N], c[N];
int x[N];
int f(int i, int x) { return a[i] * x * x + b[i] * x + c[i]; }

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i] >> b[i] >> c[i];
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  rep(i, 1, n) pq.push(pii(f(i, ++x[i]), i));
  while (m--) {
    pii now = pq.top();
    pq.pop();
    cout << now.first << ' ';
    int i = now.second;
    pq.push(pii(f(i, ++x[i]), i));
  }
  return 0;
}